﻿using System;
using System.Linq;
using System.Web;
using AB.ServiceDirectory.Entities;

namespace AB.ServiceDirectory.Design.Org
{
    public partial class AddASupportingMaterials : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack)
            {
                LoadData();
            }
        }

        private void LoadData()
        {

            DropDownListType.DataSource = BO.ASupportingMaterialBo.LoadAllType().ToList();
            DropDownListType.DataBind();
            TextBoxAddedBy.Text = HttpContext.Current.User.Identity.Name;
            TextBoxAddedDate.Text = String.Format("{0:dd/MM/yyyy}", DateTime.Now);

        }


        protected void ButtonSave_Click(object sender, EventArgs e)
        {
           var supportingMaterial= new SupportingMaterial();
            supportingMaterial.Url = TextBoxURL.Text;

            // fix cung  vi chua co session
            supportingMaterial.UserId =1;
            supportingMaterial.Description = TextBoxDescription.Text;
            supportingMaterial.AddedDate = DateTime.Now;
            supportingMaterial.IsActive = true;
            supportingMaterial.OrganisationId = 2;
            supportingMaterial.Type = DropDownListType.SelectedValue;
            bool insertSupportingMaterial= BO.ASupportingMaterialBo.InsertSupportingMaterial(supportingMaterial);
            if(insertSupportingMaterial)
            {
                Response.Redirect("~/Organisation/ASupportingMaterials.aspx");
            }
            else
            {
                Response.Write("<script>alert('Insert To Database Failed!')</script>");
            }
        }
    }
}